<?php
namespace api\jeu\perso\buff;

abstract class Buff {

	private $_value;
	private $_source;
	
	private $_valuePercent;
	private $_valueAbsolute;
	
	private $_stack;
	
	private $_multiplier;
	
	private $_rebuffs = null;
	
	private $_dead;
	private $_rebuff;
	
	public function __construct($value, $source = null, $valuePercent = false, $valueAbsolute = false, $stack = 1, $multiplier = 1, $rebuffs = null)
	{
		$this->_value = $value;
		$this->_source = $source;
		$this->_valuePercent = $valuePercent;
		$this->_valueAbsolute = $valueAbsolute;
		$this->_stack = $stack;
		$this->_multiplier = $multiplier;
		
		if(is_array($rebuffs))
		{
			$this->_rebuffs	= $rebuffs;
		}
		
		$this->_dead = false;
		$this->_rebuff = false;
	}

	public function isDead()
	{
		return $this->_dead;
	}
	
	public function isRebuff()
	{
		return $this->_rebuff;
	}	
	
	public function tick()
	{
		$this->_value *= $this->_multiplier;
		$this->_stack--;
		
		if(this->_stack <= 0)
		{
			if($this->_rebuffs)
			{
				$this->_rebuff = true;
			} 
			else
			{
				$this->_dead = true;
			}		
		}
	}
	
	public abstract function update(Buff $buff);
	
	public function getValue()
	{
		return $this->_value;
	}
	
	public function getSource()
	{
		return $this->_source;
	}
	
	public function setValue($val)
	{
		$this->_value = $val;
		return $this;
	}
	
	public function setSource($val)
	{
		$this->_source = $val;
		return $this;
	}
	
	public function apply($modifier,$source)
	{
		return $this->applyRules($modifier);
	}
	
	public abstract function applyRules($val);
	
}